var t, e = require("../../../@babel/runtime/helpers/objectSpread2"), a = require("../../../@babel/runtime/helpers/defineProperty"), i = require("../../../utils/themeSkin/skinBehavior"), s = getApp();

Page({
    data: (t = {
        id: "",
        active: 0,
        show: !1,
        code: "",
        dialog_type: 0,
        nickname: "",
        uid: "",
        name: "",
        show_tips: !1,
        timer_id: null,
        keyword: "",
        code_sn: "",
        type: "binding"
    }, a(t, "id", ""), a(t, "list", []), a(t, "current_page", 1), a(t, "last_page", 1), 
    a(t, "get_time_sort", "asc"), a(t, "active_end_sort", "asc"), a(t, "show_member_flag", !1), 
    a(t, "member_list", []), t),
    behaviors: [ i ],
    onLoad: function(t) {
        this.setData({
            get_time_sort: "desc"
        });
    },
    getData: function(t) {
        var e = this;
        s._postNetWork({
            url: s.getNetAddresss("plugin.exchange-code.api.record.list"),
            data: t,
            success: function(t) {
                var a = t.data, i = a.result, d = a.data, r = d.data, n = d.current_page, o = d.last_page, c = a.msg;
                i ? (e.setData({
                    current_page: n,
                    last_page: o
                }), 1 == n ? e.setData({
                    list: r || []
                }) : e.setData({
                    list: e.data.list.concat(r)
                })) : s.tips(c);
            }
        });
    },
    toHistory: function() {
        wx.navigateTo({
            url: "/packageI/redeem_code/history/history"
        });
    },
    showOverlay: function(t) {
        "1" == t.currentTarget.dataset.type ? this.setData({
            type: "Donation",
            code_sn: t.currentTarget.dataset.datas.code_sn,
            code_id: t.currentTarget.dataset.datas.code_id,
            id: t.currentTarget.dataset.datas.id
        }) : this.setData({
            binding: "binding"
        }), this.setData({
            show: !0,
            dialog_type: t.currentTarget.dataset.type
        });
    },
    link: function(t) {
        var e = t.currentTarget.dataset.datas, a = e.code_sn, i = e.code_id;
        wx.navigateTo({
            url: "/packageI/redeem_code/index/index?code_id=" + i + "&sn_code=" + a
        });
    },
    HideOverlay: function() {
        this.setData({
            show: !1
        });
    },
    input_handle: function(t) {
        var e = this, a = t.currentTarget.dataset.type, i = t.detail.value;
        "code" == a ? this.setData({
            code: i,
            type: "binding"
        }) : (this.setData({
            keyword: i,
            type: "presented"
        }), this.data.timer_id && clearTimeout(this.data.timer_id), this.data.timer_id = setTimeout(function() {
            e.getMemberInfo(i);
        }, 600));
    },
    confirm: function() {
        var t = this;
        "binding" == this.data.type ? s._getNetWork({
            url: s.getNetAddresss("plugin.exchange-code.api.record.bind"),
            data: {
                sn: this.data.code
            },
            success: function(e) {
                var a = e.data, i = a.result, d = a.msg;
                if (s.tips(d), i) {
                    t.setData({
                        show: !1
                    });
                    var r = {}, n = t.data.active;
                    2 != n && 3 != n || (r.search = {
                        type: n - 1
                    }), 0 != n && 1 != n || (r.order = 0 == n ? {
                        get_time: "desc"
                    } : {
                        active_end: "desc"
                    }), t.getData(r);
                }
            }
        }) : s._getNetWork({
            url: s.getNetAddresss("plugin.exchange-code.api.record.tranfer"),
            data: {
                uid: this.data.uid,
                id: this.data.id
            },
            success: function(e) {
                var a = e.data, i = a.result, d = a.msg, r = a.data, n = r.title, o = r.imgUrl, c = r.desc;
                s.tips(d), i && (wx.setStorageSync("wxShareInfo", {
                    title: n,
                    imgUrl: o,
                    description: c
                }), setTimeout(function() {
                    wx.navigateTo({
                        url: "/packageI/redeem_code/index/index?share=1&code_id=" + t.data.code_id + "&sn_code=" + t.data.code_sn
                    });
                }, 300));
            }
        });
    },
    getMemberInfo: function(t) {
        var e = this;
        s._getNetWork({
            url: s.getNetAddresss("plugin.exchange-code.api.record.memberSearch"),
            data: {
                keyword: t
            },
            success: function(t) {
                var a = t.data, i = a.result, d = a.msg, r = a.data.data;
                i ? (r && 0 !== r.length && e.setData({
                    member_list: r,
                    show_member_flag: !0,
                    show_tips: !1
                }), 0 == r.length && e.setData({
                    show_tips: !0,
                    member_list: [],
                    show_member_flag: !1
                })) : s.tips(d);
            }
        });
    },
    choose_handle: function(t) {
        var e = t.currentTarget.dataset.item, a = e.uid, i = e.mobile, s = e.nickname, d = e.name;
        this.setData({
            uid: a,
            nickname: s,
            name: d,
            keyword: i || a,
            show_member_flag: !1
        });
    },
    onChange: function(t) {
        var e = t.detail.index, a = this.get_tab_params(e);
        console.log(a, "json"), this.getData(a), this.setData({
            active: t.detail.index
        });
    },
    get_tab_params: function(t) {
        var e = {};
        return 2 != t && 3 != t || (e.search = {
            type: t - 1
        }), 0 != t && 1 != t || (0 == t ? ("asc" == this.data.get_time_sort ? this.data.get_time_sort = "desc" : this.data.get_time_sort = "asc", 
        e.order = {
            get_time: this.data.get_time_sort
        }) : ("asc" == this.data.active_end_sort ? this.data.active_end_sort = "desc" : this.data.active_end_sort = "asc", 
        e.order = {
            active_end: this.data.active_end_sort
        })), e;
    },
    onReady: function() {},
    onShow: function() {
        var t = {}, e = this.data.active;
        2 != e && 3 != e || (t.search = {
            type: e - 1
        }), 0 != e && 1 != e || (t.order = 0 == e ? {
            get_time: this.data.get_time_sort
        } : {
            active_end: this.data.active_end_sort
        }), this.getData(t);
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (!(this.data.current_page >= this.data.last_page)) {
            var t = {}, a = this.data.active;
            2 != a && 3 != a || (t.search = {
                type: a - 1
            }), 0 != a && 1 != a || (t.order = 0 == a ? {
                get_time: this.data.get_time_sort
            } : {
                active_end: this.data.active_end_sort
            }), this.getData(e({
                page: this.data.current_page + 1
            }, t));
        }
    },
    onShareAppMessage: function() {}
});